import { get, post, put, del, exportRequest } from '@/utils/request';
import {DeptInfo} from '@/api/system/login';
import {SysPost} from "@/api/system/post";
import {BaseResponse} from "@/api/system/index.ts";
import {SysRole} from "@/api/system/role.ts";

export interface SysUser extends BaseResponse{
    admin: boolean;
    avatar: string;
    delFlag: string;
    dept: DeptInfo;
    deptId: number;
    deptName: string;
    email: string;
    loginDate: string;
    loginIp: string;
    nickName: string;
    password: string;
    phonenumber: string;
    remark: string;
    roles: SysRole[];
    roleId: number;
    roleIds: number[];
    sex: string;
    status: string;
    userId: number;
    userName: string;
    userType: string;
}
export interface DeptTreeInfo {
    key?: number;
    title?: string;
    children?: DeptTreeInfo[];
}
export interface UserListParams {
    deptId: number;
    pageSize: number;
    pageNum: number;
}
export interface UserResponse {
    rows: SysUser[];
    total: number;
}
export interface UserDetailProps {
    data: SysUser;
    postIds: number[];
    posts: SysPost[];
    roleIds: number[];
    roles: SysRole[];
}
// 获取用户部门
export const getDeptTreeApi = () => {
    return get<DeptTreeInfo[]>('/system/user/deptTree');
};

// 获取用户列表
export const getUserListApi = (data: UserListParams) => {
    return get<UserResponse>('/system/user/list', data);
};
// 获取用户列表
export const getUserDetailApi = (userId: any) => {
    return get<UserDetailProps>(`/system/user/${userId}`);
};
// 新增用户
export const insetUserApi = (data: SysUser) => {
    return post('/system/user', data);
};

// 编辑用户
export const updateUserApi = (data: SysUser) => {
    return put('/system/user', data);
};

// 删除用户
export const deleteUserApi = (userId: any) => {
    return del(`/system/user/${userId}`);
};

// 用户列表导入
export const downloadUserTemplateApi = () => {
    return post(`/system/user/importTemplate`);
};

// 用户列表导入
export const importUserListApi = (data?: any) => {
    return post(`/system/user/importData`, data);
};

// 用户列表导出
export const exportUserListApi = (data?: any) => {
    return exportRequest(`/system/user/export`, data);
};
// 修改用户状态
export const changeUserStatusApi = (params: any) => {
    return put('/system/user/changeStatus', params);
};